﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

namespace ElingOA6_Admin_DSJCJ.BLL
{
    /// <summary>
    /// 工作组岗位BLL
    /// </summary>
    public class HRWorkGrpDuty
    {
        /// <summary>
        /// 工作组岗位DAL
        /// </summary>
        private readonly DAL.HRWorkGrpDuty dal = new DAL.HRWorkGrpDuty();
        
        /// <summary>
        /// 获取数据列表
        ///<creator>zhongyl</creator>
        /// <date>2013-07-12</date>
        /// </summary>
        /// <param name="strWhere">查询条件</param>
        /// <returns>工作组岗位数据列表</returns>
        public List<Model.HRWorkGrpDuty> GetModelList(string strWhere)
        {
            DataSet ds = dal.GetList(strWhere);
            return DataTableToList(ds.Tables[0]);
        }

        /// <summary>
        /// 删除一条数据
        ///<creator>zhongyl</creator>
        /// <date>2013-07-12</date>
        /// </summary>
        /// <param name="fEntityNo">组织机构编号</param>
        /// <param name="fWorkGrpNo">工作组编号</param>
        /// <param name="fWorkGrpDutyNo">工作组岗位编号</param>
        public void Delete(string fEntityNo, string fWorkGrpNo, string fWorkGrpDutyNo)
        {

            dal.Delete(fEntityNo, fWorkGrpNo, fWorkGrpDutyNo);
        }

        /// <summary>
        /// 获得数据列表
        ///<creator>zhongyl</creator>
        /// <date>2013-07-12</date>
        /// </summary>
        /// <param name="strWhere">sql查询条件</param>
        /// <returns>数据列表</returns>
        public DataSet GetList(string strWhere)
        {
            return dal.GetList(strWhere);
        }

        /// <summary>
        /// 是否存在该记录
        ///<creator>zhongyl</creator>
        /// <date>2013-07-12</date>
        /// </summary>
        /// <param name="fEntityNo">组织机构编号</param>
        /// <param name="fWorkGrpNo">工作组编号</param>
        /// <param name="fWorkGrpDutyNo">工作组岗位编号</param>
        /// <returns>工作组岗位数据列表</returns>
        public bool Exists(string fEntityNo, string fWorkGrpNo, string fWorkGrpDutyNo)
        {
            return dal.Exists(fEntityNo, fWorkGrpNo, fWorkGrpDutyNo);
        }
        /// <summary>
        /// 获得数据列表
        ///<creator>zhongyl</creator>
        /// <date>2013-07-12</date>
        /// </summary>
        /// <param name="dt">需转换数据源</param>
        /// <returns>转换后数据列表</returns>
        public List<Model.HRWorkGrpDuty> DataTableToList(DataTable dt)
        {
            List<Model.HRWorkGrpDuty> modelList = new List<Model.HRWorkGrpDuty>();
            int rowsCount = dt.Rows.Count;
            if (rowsCount > 0)
            {
                Model.HRWorkGrpDuty model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = new Model.HRWorkGrpDuty();
                    model.FEntityNo = dt.Rows[n]["FEntityNo"].ToString();
                    model.FWorkGrpNo = dt.Rows[n]["FWorkGrpNo"].ToString();
                    model.FDutyProp = dt.Rows[n]["FDutyProp"].ToString();
                    model.FWorkGrpDutyNo = dt.Rows[n]["FWorkGrpDutyNo"].ToString();
                    if (dt.Rows[n]["FSeq"].ToString() != "")
                    {
                        model.FSeq = int.Parse(dt.Rows[n]["FSeq"].ToString());
                    }
                    model.FDutyName = dt.Rows[n]["FDutyName"].ToString();
                    modelList.Add(model);
                }
            }
            return modelList;
        }

        /// <summary>
        /// 获得数据列表
        ///<creator>zhongyl</creator>
        /// <date>2013-07-12</date>
        /// </summary>
        /// <param name="dt">需转换数据源</param>
        /// <returns>转换后数据列表</returns>
        public List<ElingOA6_Admin_DSJCJ.Model.HRWorkGrpMember> DataTableToHRWorkGrpMemberList(DataTable dt)
        {
            List<ElingOA6_Admin_DSJCJ.Model.HRWorkGrpMember> modelList = new List<ElingOA6_Admin_DSJCJ.Model.HRWorkGrpMember>();
            int rowsCount = dt.Rows.Count;
            if (rowsCount > 0)
            {
                ElingOA6_Admin_DSJCJ.Model.HRWorkGrpMember model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = dal.DataRowToHRWorkGrpMemberModel(dt.Rows[n]);
                    if (model != null)
                    {
                        modelList.Add(model);
                    }
                }
            }
            return modelList;
        }


    }
}
